/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package music.types;

import MidiGui.MusicFonts;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;
import music.SpacingOptions;
import music.TimeSignature;

/**
 *
 * @author TJ
 */
public enum NoteTypes {
    WHOLE(1,0xF077,(char)0xF0B7,(char)0xF077),
    HALF(2,0xF068,(char)0xF0B7,(char)0xF048),
    QUARTER(4,0xF071,(char)0xF0CE,(char)0xF051),
    EIGTH(8,0xF065,(char)0xF0E4,(char)0xF045),
    SIXTEENTH(16,0xF078,(char)3,(char)0xF058),
    _32(32,0x0000,(char)3,(char)0xF000),
    _64(64,0x0000,(char)3,(char)0xF000),
    _128(128,0x0000,(char)3,(char)0xF000);
    private int time;
    private char character,rest, upsideDownChar;
    private NoteTypes(int t, int c, char restChar,char upsideDown) {
        time=t;
        character=(char)c;
        rest=restChar;
        upsideDownChar=upsideDown;
    }
    public int getTime(){return time;}
    public char getCharacter() {return character;}
    public char getRest() {return rest;}
    public void render(Graphics g,int x, int y,SpacingOptions s, boolean down) {
        
        Font old=g.getFont();
        g.setFont(s.getRenderFont("OpusRegular"));
        if(down) {
            g.drawString(""+upsideDownChar, x, y);
        }else {
        g.drawString(""+character, x, y);
        }
        g.setFont(old);
    }
    public void renderRest(Graphics g,int bottomLine, SpacingOptions s, int x) {
        g.setFont(s.getRenderFont("OpusRegular"));
        Font old=g.getFont();
        g.drawString(""+rest, x, bottomLine-2*s.getLineSpacing());
        g.setFont(old);
    }
    public static Vector<NoteTypes> getNotesWithin(TimeSignature t, double f){
        Vector<NoteTypes> a=new Vector<NoteTypes>();
        for(NoteTypes n : NoteTypes.values()) {
            if(n.getLength(t)<=f) {
                a.add(n);
                f-=n.getLength(t);
            }
        }
        return a;
        
    }
    public double getLength(TimeSignature t){
        return ((double)t.getBeatType().getTime()/getTime());
    }
}
